package com.zhdl.modules.demo.task;

import com.project.command.faq.state.LinkStateService;
import com.zhdl.common.ytools.callback.CommonCallback;
import com.zhdl.hardware_contact.hardware_config.entity.ProjectConfiguration;
import com.zhdl.modules.process.service.ProjectConfigProcessService;
import com.zhdl.network.strategy.common_client.CommonProtocolService;
import com.zhdl.network.strategy.common_server.impl.CommonServerSendServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @Author: zhangyy
 * @Email: zhang10092009@hotmail.com
 * @Date: 2023/7/13 15:18:56
 * @Version: v1.0
 * @Modified:
 * @Description:
 */
@Slf4j
@Component
public class TaskDemoTest {

//    @Scheduled(fixedRate = 2000, initialDelay = 30 * 1000)
//    public void task1() {
//        log.debug("启动后30秒运行一次，以后每隔两秒运行一次");
//    }

    @Resource
    private ProjectConfigProcessService projectConfigProcessService;

    @Autowired
    private CommonProtocolService commonProtocolService;

    @Resource
    private CommonServerSendServiceImpl commonServerSendServiceImpl;

    @Resource
    private LinkStateService linkStateService;

    @Scheduled(fixedRate = 1000, initialDelay = 1000)
    public void myTask() {
//        Map<String, Boolean> allPortStates =
//                linkStateService.getAllPortStates();
//        if (allPortStates != null) {
//            log.info("allPortStates={}", allPortStates);
//        } else {
//            log.info("allPortStates=null");
//        }
    }

    @Scheduled(fixedRate = 2000000, initialDelay = 2 * 1000)
    public void task() {
//        commonProtocolService.sendCmd("1", "1111", new CommonCallback<String>() {
//            @Override
//            public void statusCallback(String s) {
//                log.info("com1-->{}",s);
//            }
//        });
//        commonProtocolService.sendCmd("2", "2222", new CommonCallback<String>() {
//            @Override
//            public void statusCallback(String s) {
//                log.info("com2-->{}",s);
//            }
//        });
//        commonProtocolService.sendCmd("127.0.0.1:6666", "6666", new CommonCallback<String>() {
//            @Override
//            public void statusCallback(String s) {
//                log.info("127.0.0.1:6666-->{}",s);
//            }
//        });
//        commonProtocolService.sendCmd("127.0.0.1:8888", "8888", new CommonCallback<String>() {
//            @Override
//            public void statusCallback(String s) {
//                log.info("127.0.0.1:8888-->{}",s);
//            }
//        });
//
//        commonServerSendServiceImpl.sendToClientCmd("127.0.0.1:6000","127.0.0.1","6000");
//        commonServerSendServiceImpl.sendToClientCmd("127.0.0.1:8000","127.0.0.1","8000");

//        projectConfigProcessService.setChangeCallBacks(Collections.singletonList(new CommonCallback<List<ProjectConfiguration>>() {
//            @Override
//            public void statusCallback(List<ProjectConfiguration> projectConfigurations) {
//                int a=0;
//                for (ProjectConfiguration projectConfiguration : projectConfigurations) {
//                    a++;
//                }
//                log.info("l:{} , {}",a,projectConfigurations.toString());
//            }
//        }));


    }

    @Scheduled(cron = "0 5 0 * * ?")
    public void test2() {
//        log.info("每天凌晨 0 点 5 分执行任务的表达式");
    }

    @Scheduled(cron = "0 18 10-16 * * ?")
    public void test3() {
//        log.info("每天 10 点到 16 点的 18 分定点执行生效的表达式");
    }
}
